var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    teamList: [],


    addishow:false
  },



  // 9.76.家属列表
  getFamilyList() {
    let t = this
    wx.showLoading({
      title: '加载中...', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })

    wx.request({
      url: app.globalData.Interfaceurl + 'getFamilyList',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,

      },
      success: res => {
        wx.hideLoading();
        console.log(res)
        t.setData({
          teamList :res.data.familyList
        })
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },
  // 74.添加/修改家属
  saveFamily() {
    let t = this

    wx.showLoading({
      title: '加载中...', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })

    wx.request({
      url: app.globalData.Interfaceurl + 'saveFamily',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        token:t.data.token,
        name:t.data.name,
        mobile:t.data.phone
      },
      success: res => {
        wx.hideLoading();
        console.log(res)
       
      
     if(res.data.result==0){
      t.setData({
        addishow:false
      })
     }else{
      wx.showToast({
        title:res.data.message,
        icon:'none'
      })
      t.setData({
        token:app.token()
      })
     }

      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
            icon: 'none', //图标
        })
      }
    })
  },

  delFamily() {
    let t = this

    wx.showLoading({
      title: '加载中...', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })

    wx.request({
      url: app.globalData.Interfaceurl + 'delFamily',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        token:t.data.token,
        familyId:'1578926341641383936'
      },
      success: res => {
        wx.hideLoading();
        console.log(res)
      
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },


  hideaddishow(){
    this.setData({
      addishow:false
    })
  },

  sumbit(){
    if (this.data.name == '') {
      wx.showToast({
        title: '请输入姓名',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
      return
    }
    if (this.data.phone == '') {
      wx.showToast({
        title: '请输入手机号',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
      return
    }
    this.saveFamily()
  },




  bindPlone(e) {
    console.log(e)
    let phone = e.detail.value
    let phoneCodeVerification = /^[1][0-9]{10}$/;
    if (!phoneCodeVerification.test(phone)) {
      wx.showToast({
        title: '您输入手机号码输入不正确',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
      this.setData({
        phone: ""
      })
    } else {

    }

  },





  addteam(){
    this.setData({
      addishow:true
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getFamilyList()
    // this.delFamily()

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      token: app.token()
    })
    if (!this.data.isonLoad) {




      if (wx.getStorageSync('istab') == true) {
        this.setData({
          pageNo: 1,
          pageSize: 10
        })
        if (app.globalData.identity == 4) {
          this.getBricklayList()
        } else if (app.globalData.identity == 1) {

          this.getSalesmanTeamPage()
        }else if(app.globalData.identity == 2){
          this.getAgentTeamPage()
        }else if(app.globalData.identity == 3){
          if(this.data.typeindex==0){
            this.getShopownerTeamPage()
          }else{
            this.getSuperviseTeamPage()
          }
        }



       


      }
    } else {
      this.setData({
        isonLoad: false
      })
  
    }
    wx.setStorageSync('istab', false)
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (app.globalData.identity == 1) {
      if (this.data.pageNo >= this.data.last) {
        return
      }
      this.setData({
        pageNo: this.data.pageNo + 1
      })
      this.getSalesmanTeamPage()
    }else if(app.globalData.identity == 2){
      if (this.data.pageNo >= this.data.last) {
        return
      }
      this.setData({
        pageNo: this.data.pageNo + 1
      })
      this.getAgentTeamPage()
    }else if(app.globalData.identity == 2){
      if (this.data.pageNo >= this.data.last) {
        return
      }
      this.setData({
        pageNo: this.data.pageNo + 1
      })
      if(this.data.typeindex==0){
        this.getShopownerTeamPage()
      }else{
        this.getSuperviseTeamPage()
      }
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },



  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})